package homework;

/**
 * 编写一个类Calculator,有两个属性num1,num2,这两个数据的值，不能在定义的同时初始化，最后实现加减乘除四种运算.
 */
public class Main {
    public static void main(String[] args) {
        double num1 = 1;
        double num2 = 2;
        Calculator calculator = new Calculator(num1, num2);
        double sum = calculator.sum();
        double sub = calculator.subtract();
        double mul = calculator.multiply();
        double div = calculator.divide();
        System.out.println(num1 + " + " + num2 + " = " + sum);
        System.out.println(num1 + " - " + num2 + " = " + sub);
        System.out.println(num1 + " * " + num2 + " = " + mul);
        if (div != -1) {
            System.out.println(num1 + " / " + num2 + " = " + div);
        }
    }
}

class Calculator {
    private double num1;
    private double num2;

    public Calculator(double num1, double num2) {
        this.num1 = num1;
        this.num2 = num2;
    }

    public double sum() {
        return num1 + num2;
    }

    public double subtract() {
        return num1 - num2;
    }

    public double divide() {
        if (num2 != 0) {
            return num1 / num2;
        }
        System.out.println("除数不能为零");
        return -1;
    }

    public double multiply() {
        return num1 * num2;
    }
}
